/*!
// DatatypeExp v1.0
// Copyright 2015 OrChange Inc. All rights reserved.
// Licensed under the MIT License.
*/
/*jslint vars: true, sloppy: true, nomen: true, plusplus: true */
/*global Exp: false */

/**
 * String pattern expression object.
 * Extend from RegExp.
 *
 * @class NumberExp
 * @constructor
 * @param {string} exp
 */
expPattern.stringExpPattern = /^\/(.*)?$/;
var StringExp = function StringExp(exp) {
	Exp.apply(this, arguments);

	if (expPattern.stringExpPattern.test(exp)) {
		if (this.exp === '/') {
			return;
		}
		this.pattern = new RegExp(this.exp.substr(1));
	} else {
		throw new SyntaxError('Expression: "' + exp + '" is not a valid string pattern!');
	}
};
StringExp.prototype = new Exp();
StringExp.prototype.constructor = StringExp;

StringExp.prototype.$test = function (string) {
	if (typeof string !== 'string') {
		return false;
	}

	if (this.exp === '/') {
		return true;
	}

	return this.pattern.test(string);
};
